/**
 * 
 */
package com.zeba.orderbook;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;

import com.zeba.R;

/**
 * @author Zeba
 *
 */
public class OrderBookActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.orderbook);

        TableLayout tl = (TableLayout)findViewById(R.id.orderbook_maintable);
        TableRow headingRow = new TableRow(this);
    	TextView scripHeading = new TextView(this);
    	scripHeading.setText("SCRIP");
    	scripHeading.setPadding(30,5,5,5);
    	scripHeading.setTextColor(Color.BLUE);
    	TextView actionHeading = new TextView(this);
    	actionHeading.setText("ACTION");
    	actionHeading.setPadding(5,5,5,5);
    	actionHeading.setTextColor(Color.BLUE);
    	TextView dateHeading = new TextView(this);
    	dateHeading.setText("DATE");
    	dateHeading.setPadding(5,5,5,5);
    	dateHeading.setTextColor(Color.BLUE);
    	TextView statusHeading = new TextView(this);
    	statusHeading.setText("STATUS");
    	statusHeading.setPadding(5,5,5,5);
    	statusHeading.setTextColor(Color.BLUE);
    	TextView priceHeading = new TextView(this);
    	priceHeading.setText("PRICE");
    	priceHeading.setPadding(5,5,5,5);
    	priceHeading.setTextColor(Color.BLUE);
    	TextView commissionHeading = new TextView(this);
    	commissionHeading.setText("COMMISSION");
    	commissionHeading.setPadding(15,5,30,5);
    	commissionHeading.setTextColor(Color.BLUE);
    	headingRow.addView(scripHeading);
    	headingRow.addView(actionHeading);
    	headingRow.addView(dateHeading);
    	headingRow.addView(statusHeading);
    	headingRow.addView(priceHeading);
    	headingRow.addView(commissionHeading);
    	tl.addView(headingRow);
        
        List<OrderBookEntry> entries = getOrderBookEntries();
        
        Iterator<OrderBookEntry> iter = entries.iterator();
        while(iter.hasNext()){
        	
        	OrderBookEntry item = iter.next();
        	
        	TableRow tr = new TableRow(this);
	        tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
				TextView scripEntry = new TextView(this);
					scripEntry.setText(item.getScrip());
					scripEntry.setPadding(30,5,5,5);
				TextView actionEntry = new TextView(this);
					actionEntry.setText(item.getAction());
					actionEntry.setPadding(5,5,5,5);
				TextView dateEntry = new TextView(this);
					dateEntry.setText(item.getDate());
					dateEntry.setPadding(5,5,5,5);
				TextView statusEntry = new TextView(this);
					statusEntry.setText(item.getStatus());
					statusEntry.setPadding(5,5,5,5);
				TextView priceEntry = new TextView(this);
					priceEntry.setText(item.getPrice());
					priceEntry.setPadding(5,5,5,5);
				TextView commissionEntry = new TextView(this);
					commissionEntry.setText(item.getCommission());
					commissionEntry.setPadding(15,5,30,5);
		    tr.addView(scripEntry);
		    tr.addView(actionEntry);
		    tr.addView(dateEntry);
		    tr.addView(statusEntry);
		    tr.addView(priceEntry);
		    tr.addView(commissionEntry);
		    
		    tl.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        }
        System.out.println("test");
	}

	private List<OrderBookEntry> getOrderBookEntries() {

		OrderBookEntry entry1 = new OrderBookEntry();
		entry1.setAction("SELL");
		entry1.setCommission("10");
		entry1.setDate("Test");
		entry1.setPrice("100");
		entry1.setScrip("SBIN");
		entry1.setStatus("Complete");
		
		OrderBookEntry entry2 = new OrderBookEntry();
		entry2.setAction("BUY");
		entry2.setCommission("10");
		entry2.setDate("Test");
		entry2.setPrice("100");
		entry2.setScrip("GOOG");
		entry2.setStatus("Complete");
		
		OrderBookEntry entry3 = new OrderBookEntry();
		entry3.setAction("BUY");
		entry3.setCommission("10");
		entry3.setDate("Test");
		entry3.setPrice("100");
		entry3.setScrip("ORCHI");
		entry3.setStatus("Complete");
		
		OrderBookEntry entry4 = new OrderBookEntry();
		entry4.setAction("SELL");
		entry4.setCommission("10");
		entry4.setDate("Test");
		entry4.setPrice("100");
		entry4.setScrip("TATMOT");
		entry4.setStatus("InProcess");
		
		List<OrderBookEntry> result = new ArrayList<OrderBookEntry>();
		result.add(entry1);
		result.add(entry2);
		result.add(entry3);
		result.add(entry4);
		
		return result;
	}
		
}	
